
jQuery.fn.tablexise = function(settings) {
  
  var config = {'oddrowclass': 'odd','openclass':'plus','closeclass':'minus','expandedrowclass':'onexpand'};
  
  if (settings) $.extend(config, settings);
  
  return this.each(function(){
    //Apply odd row styles    
    $("#"+$(this).attr('id')+" tr:odd").addClass(config.oddrowclass);
    
    //For all odd rows, set its state to "collapsed"
    $("#"+$(this).attr('id')+" tr:odd").attr("state","collapsed");
    
    $("#"+$(this).attr('id')+" .tablex-expander").addClass(config.openclass);
          
    //Hide the alternate rows
    $("#"+$(this).attr('id')+" tr:not(.odd)").hide();
    
    //Show the header row
    $("#"+$(this).attr('id')+" tr:first-child").show();
          
    //Bind the click event of the expander button
    $("#"+$(this).attr('id')+" .tablex-expander").click(function(){  
		if($(this).parent().attr("state")=="collapsed")
		{		    
			$(this).parent().next("tr").show();      //Show the next row i.e. expanded row			
			$(this).parent().attr('state','expanded');			//Set the state of the current row as "expanded"
			$(this).addClass(config.closeclass);
			$(this).removeClass(config.openclass);
			$(this).parent().children().addClass(config.expandedrowclass);				
		}else{
			$(this).parent().next("tr").hide();
			$(this).parent().attr('state','collapsed');  			
			$(this).addClass(config.openclass);
			$(this).removeClass(config.closeclass); 
			$(this).parent().children().removeClass(config.expandedrowclass);
		}
	});
  });
};